﻿package com.indigon.parkStory
{
	import com.indigon.parkStory.control.ControlMain;
	import com.indigon.parkStory.data.GameData;
	import com.indigon.parkStory.data.UserData;
	import com.indigon.parkStory.model.ModelMain;
	import com.indigon.parkStory.ui.IndexScreen;
	import com.indigon.parkStory.ui.SplashScreen;
	import com.indigon.parkStory.view.SoundMain;
	import com.indigon.parkStory.view.ViewMain;
	import com.indigon.utils.PerformanceMonitor;
	import com.indigon.utils.SoundManager;
	
	import flash.display.Sprite;
	import flash.events.Event;
	
	[ResourceBundle("ui")]
	public class ParkStoryLauncher extends Sprite
	{
		public static const WEB 	: uint = 0;
		public static const ANDROID : uint = 1;
		public static const IOS	    : uint = 2;
		
		public static const FRAMERATE : uint = 30;
		
		private var _type : uint;
		
		private var _gameModel    : ModelMain;
		private var _gameSound    : SoundMain;
		private var _gameControl  : ControlMain;
		private var _gameView     : ViewMain;
		
		private var _indexScreen  : IndexScreen;
		private var _splashScreen : SplashScreen;
		
		public function ParkStoryLauncher(type:uint)
		{
			this._type = type;
		}
		
		public function init(levelsClass:Class):void
		{
			UserData.instance.init();
			GameData.instance.init(levelsClass);
			SoundManager.instance.init();
			
			if (stage != null)
			{
				launch();
			}
			else
			{
				addEventListener(Event.ADDED_TO_STAGE, launch);
			}
		}
			
		private function launch(e:Event=null):void
		{
			removeEventListener(Event.ADDED_TO_STAGE, launch);
			
			_gameModel    = new ModelMain(FRAMERATE);
			_gameView     = new ViewMain(_gameModel);
			_gameSound    = new SoundMain(_gameModel);
			_gameControl  = new ControlMain(_gameModel, _gameView, _gameSound, stage);
			
			_indexScreen  = new IndexScreen();
			_splashScreen = new SplashScreen();
			
			this.addChild(_gameView);
			
			this.addChild(new PerformanceMonitor());
			
			_gameControl.config(GameData.instance.getLevel(0, 1));
			_gameControl.start();
		}
		
		/**
		 * scaling class.
		 * fix frog rotation on lillies.
		 * multiplier stars no longer count... the base star is useless?
		 * cluster screen.
		 * splash screen (with info button, sound button and exit).
		 * improve graphics of objects with ripples around them.
		 * backgrounds.
		 * map editor.
		 */
		
		/** IDEAS:
		 * a frog that jump automatically between lillies. our frog cannot be on the same lilly.
		 * strong flows, wind and whirpools.
		 * moving crocodilies by beizers.
		 */
		
		/** UNLOCKABLES:
		 * frog colors.
		 * frogs hats.
		 * other frog sounds.
		 * other frogs (zombie frog).
		 */
		
		/** NEED TO DO:
		 * jewels.
		 * unlockables in cluster screen.
		 * highscore on summary and save highscore.
		 * summary screen animations when gaining score.
		 * basic ui (splash / menu / sound / index).
		 * tutorial (help screen).
		 * blitting engine.
		 * frog reflection on water.
		 * lillies reflections.
		 */
	}
}